<?php
include("header.php");
include("functions.php");

if($_SESSION['user_level'] != 1 )
{
	header("location: redirect.php");
}
else
 {

$pageTitle = "Email Settings";
$smtp = get_value_of('$smtp'); 
$smtp = str_replace ("//local or smtp","",$smtp); $smtp =trim($smtp);
if ($smtp == "") {$smtp="local";}
if ($smtp == "smtp") {$smtpyes="checked"; $smtpno="";}
if ($smtp != "smtp") {$smtpyes=""; $smtpno="checked";}


$smtp_server = get_value_of('$smtp_server'); $smtp_server =trim($smtp_server); 
$smtp_secure = get_value_of('$smtp_secure'); $smtp_secure =trim($smtp_secure); 
$smtp_port = get_value_of('$smtp_port'); $smtp_port =trim($smtp_port); 
$smtp_username = get_value_of('$smtp_username'); $smtp_username =trim($smtp_username); 
$smtp_password = get_value_of('$smtp_password'); $smtp_password =trim($smtp_password); 

$disable_email = get_value_of('$disable_email'); 
$disable_email =trim($disable_email);

if ($disable_email == 1) {$diyes="checked"; $dino="";}
if ($disable_email != 1) {$diyes=""; $dino="checked";}

if($_SERVER['REQUEST_METHOD'] != 'POST')
{ 
$tags = array( '{TITLE}','{SMTP}','{SMTP_VALUE}','{SMTP_SERVER}','{SMTP_SERVER_VALUE}'
,'{SMTP_SECURE}','{SMTP_SECURE_VALUE}','{SMTPYES}','{SMTPNO}','{SMTP_SECURE}','{SMTP_SECURE_VALUE}','{SMTP_PORT}','{PORT_VALUE}','{SMTP_UN}','{SMTP_UN_VALUE}','{SMTP_PW}','{SMTP_PW_VALUE}','{CONFIRM}','{DISABLE_EMAIL}','{D_EMAIL_Y}','{D_EMAIL_N}'
);

$data = array( 'Email Settings','Smtp',$smtp,"Smtp server",$smtp_server,'Smtp secure',$smtp_secure,$smtpyes ,$smtpno,'Smtp Secure',$smtp_secure,'Smtp port',$smtp_port,'Smtp username',$smtp_username,'Smtp password',$smtp_password,'Confirm','Disable email subscription',$diyes,$dino );

echo str_replace($tags, $data, file_get_contents("./style/".$default_style."/email.html"));	 
}
else
{
//SMTP yes/no
if ($_POST['smtp'] == 1) {$smtp_ = "smtp";}
if ($_POST['smtp'] != 1) {$smtp_ = "local";}
write_value_of('$smtp',"$smtp",$smtp_);
//SMTP server
write_value_of('$smtp_server',"$smtp_server",$_POST['smtp_server']);
//SMTP secure
write_value_of('$smtp_secure',"$smtp_secure",$_POST['smtp_secure']);
//SMTP port
write_value_of('$smtp_port',"$smtp_port",$_POST['smtp_port']);
//SMTP username
write_value_of('$smtp_username',"$smtp_username",$_POST['smtp_un']);
//SMTP password
write_value_of('$smtp_password',"$smtp_password",$_POST['smtp_pw']);

write_value_of('$disable_email',"$disable_email",$_POST['dis_email']);

echo "<b>Information</b><hr><br /><div align='center'>Configuration updated successfully.<br /><br /><a href = 'email.php'>Back to previous page</a></div>";
}
$pageContents = ob_get_contents (); // Get all the page's HTML into a string
ob_end_clean (); // Wipe the buffer 
echo str_replace ('<!--TITLE-->', $pageTitle, $pageContents);  	
}


?>
